package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.MrMonitorDevicePointValue;
import com.ruoyi.system.domain.vo.DeviceMonitorReponse;
import com.ruoyi.system.domain.vo.DeviceMonitorRequest;
import com.ruoyi.system.domain.vo.HistogramDataVO;
import com.ruoyi.system.service.IMrMonitorDevicePointValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备监控项-监控数据Controller
 *
 * @author ruoyi
 * @date 2022-12-04
 */
@RestController
@RequestMapping("/system/pointvalue")
public class MrMonitorDevicePointValueController extends BaseController
{
    @Autowired
    private IMrMonitorDevicePointValueService mrMonitorDevicePointValueService;

    /**
     * 查询设备监控项-监控数据列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MrMonitorDevicePointValue mrMonitorDevicePointValue)
    {
        startPage();
        List<MrMonitorDevicePointValue> list = mrMonitorDevicePointValueService.selectMrMonitorDevicePointValueList(mrMonitorDevicePointValue);
        return getDataTable(list);
    }

    /**
     * 导出设备监控项-监控数据列表
     */
    @Log(title = "设备监控项-监控数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MrMonitorDevicePointValue mrMonitorDevicePointValue)
    {
        List<MrMonitorDevicePointValue> list = mrMonitorDevicePointValueService.selectMrMonitorDevicePointValueList(mrMonitorDevicePointValue);
        ExcelUtil<MrMonitorDevicePointValue> util = new ExcelUtil<>(MrMonitorDevicePointValue.class);
        util.exportExcel(response, list, "设备监控项-监控数据数据");
    }

    /**
     * 获取设备监控项-监控数据详细信息
     */
    @GetMapping(value = "/{autoId}")
    public AjaxResult getInfo(@PathVariable("autoId") Long autoId)
    {
        return success(mrMonitorDevicePointValueService.selectMrMonitorDevicePointValueByAutoId(autoId));
    }

    /**
     * 新增设备监控项-监控数据
     */
    @Log(title = "设备监控项-监控数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MrMonitorDevicePointValue mrMonitorDevicePointValue)
    {
        return toAjax(mrMonitorDevicePointValueService.insertMrMonitorDevicePointValue(mrMonitorDevicePointValue));
    }

    /**
     * 修改设备监控项-监控数据
     */
    @Log(title = "设备监控项-监控数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MrMonitorDevicePointValue mrMonitorDevicePointValue)
    {
        return toAjax(mrMonitorDevicePointValueService.updateMrMonitorDevicePointValue(mrMonitorDevicePointValue));
    }

    /**
     * 删除设备监控项-监控数据
     */
    @Log(title = "设备监控项-监控数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{autoIds}")
    public AjaxResult remove(@PathVariable Long[] autoIds)
    {
        return toAjax(mrMonitorDevicePointValueService.deleteMrMonitorDevicePointValueByAutoIds(autoIds));
    }

    /**
     * 查询设备监控项数据，用于绘制趋势图
     */
    @PostMapping("/trendChartData")
    public AjaxResult trendChartData(@RequestBody DeviceMonitorRequest request)
    {
        DeviceMonitorReponse reponse = mrMonitorDevicePointValueService.trendChartData(request);
        return success(reponse);
    }

    /**
     * 查询设备监控项数据，用于绘制柱状图
     */
    @PostMapping("/histogramData")
    public AjaxResult histogramData(@RequestBody DeviceMonitorRequest request)
    {
        DeviceMonitorReponse reponse = mrMonitorDevicePointValueService.histogramData(request);
        HistogramDataVO histogramDataVO = new HistogramDataVO();
        histogramDataVO.setData(reponse.getData());
        histogramDataVO.setUnit(reponse.getUnit());
        return success(histogramDataVO);
    }

    /**
     * 查询设备监控项数据，用于绘制模拟图
     */
    @PostMapping("/simulationDiagramData")
    public AjaxResult simulationDiagramData(@RequestBody DeviceMonitorRequest request)
    {
        DeviceMonitorReponse reponse = mrMonitorDevicePointValueService.simulationDiagramData(request);
        return success(reponse);
    }
}
